import { getProListData } from '@/services/pro'
import { message }  from 'antd'
import { history, Effect, Reducer } from 'umi'
import { IPro } from '@/pages/pro/pro'
export interface IProState {
  proList: IPro[]
  recommendList: IPro[]
  seckillList: IPro[]
  searchList: IPro[]
}
export interface IProModel {
  namespace: 'pro',
  state: IProState,
  effects: {
    getProList: Effect
  },
  reducers: {
    changeProList: Reducer,
    changeRecommendList: Reducer,
    changeSeckillList: Reducer,
    changeSearchList: Reducer,
  }
}

const userModel: IProModel = {
  namespace: 'pro',
  state: {
    proList: [],
    recommendList: [],
    seckillList: [],
    searchList: []
  },
  effects: {
    * getProList ({ payload }: any, { call, put }: any) {
      const res = yield call(getProListData, payload)
      console.log(res.data)
      yield put({
        type: 'changeProList',
        payload: res.data.data
      })
    }

  },
  reducers: {
    changeProList (state: any, action: any) {
      state.proList = action.payload
    },
    changeRecommendList (state: any, action: any) {
      state.recommendList = action.payload
    },
    changeSeckillList (state: any, action: any) {
      state.seckillList = action.payload
    },
    changeSearchList (state: any, action: any) {
      state.searchList = action.payload
    }
  }
}

export default userModel
